package sctu.edu.java.year2016.team06.luoxin.day20160605.chapter12_1;

/**编写程序，实现读取文件时出现一个表示读取进度的进度条，可使用javax.swing包提供的输入流类ProressMoniterInputStream.
 * Created by Administrator on 2016/6/5.
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.TimeUnit;
import javax.swing.*;
public class ProgressBar {
    public static void main(String[] args) {
        JFrame frame = new JFrame("JProgressBarDemo");
        frame.setSize(400, 200);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new FlowLayout());
        final JProgressBar progressBar = new JProgressBar();
        progressBar.setOrientation(JProgressBar.HORIZONTAL);
        progressBar.setSize(200, 100);
        progressBar.setMinimum(0);
        progressBar.setMaximum(100);
        frame.add(progressBar);
        JButton btn = new JButton("Start ProgressBar");
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        for (int i = 0; i <= 10; i++) {
                            progressBar.setValue(i * 10);
                            try {
                                TimeUnit.SECONDS.sleep(1);
                            } catch (InterruptedException e1) {
                                e1.printStackTrace();
                            }
                        }
                    }
                }).start();
            }
        });        frame.add(btn);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}
